<template>
  <div>
    <div class="user-profile">
      <div class="info">
        <van-image
          round
          :src="photo"
        />
        <h3 class="name">
          {{name}}
          <br />
          <van-tag size="mini">{{birthday}}</van-tag>
        </h3>
      </div>
    </div>
    <van-row class="user-links">
      <van-col span="8">
        <van-icon
          name="newspaper-o"
          color="#7af"
        />我的作品
      </van-col>
      <van-col span="8">
        <van-icon
          name="star-o"
          color="#f00"
        />我的收藏
      </van-col>
      <van-col span="8">
        <van-icon
          name="tosend"
          color="#fa0"
        />阅读历史
      </van-col>
    </van-row>
    <!-- 编辑入口 -->
    <van-cell-group class="user-group">
      <van-cell
        icon="edit"
        title="编辑资料"
        to="/user/profile"
        is-link
      />
      <van-cell
        icon="chat-o"
        title="小智同学"
        to="/user/chat"
        is-link
      />
      <van-cell
        icon="setting-o"
        title="系统设置"
        is-link
      />
      <van-cell
        @click="outApp"
        icon="warning-o"
        title="退出登录"
        is-link
      />
    </van-cell-group>
  </div>
</template>

<script>
import { userInfo } from '@/api/user'
export default {
  name: 'user',
  data () {
    return {
      name: '',
      birthday: '',
      photo: ''
    }
  },
  async created () {
    try {
      const res = await userInfo()
      this.name = res.data.data.name
      this.birthday = res.data.data.birthday
      this.photo = res.data.data.photo
      console.log(res, 123456)
    } catch { }
  },
  methods: {
    outApp () {
      this.$dialog.confirm({
        title: '标题',
        message: '弹窗内容'
      })
        .then(() => {
          this.$store.commit('user/removeToken')
          this.$router.push('/home')
          this.$toast({
            message: '退出成功',
            icon: 'success'
          })
          // on confirm
        })
        .catch(() => {
          // on cancel
        })
      // this.$store.commit('user/removeToken')
    }
  }
}
</script>

<style lang="less" scoped>
.user-links {
  padding: 15px 0;
  font-size: 12px;
  text-align: center;
  background-color: #fff;
  .van-icon {
    display: block;
    font-size: 24px;
    padding-bottom: 5px;
  }
}
</style>
